package c.c.b.a.a;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.logging.Logger;

/* compiled from: Okio */
public final class o {
    public static final Logger a = Logger.getLogger(o.class.getName());

    /* compiled from: Okio */
    public static class a implements w {
        public final /* synthetic */ x a;
        public final /* synthetic */ InputStream b;

        public a(x xVar, InputStream inputStream) {
            this.a = xVar;
            this.b = inputStream;
        }

        public x a() {
            return this.a;
        }

        public long b(e eVar, long j) throws IOException {
            int i = (j > 0 ? 1 : (j == 0 ? 0 : -1));
            if (i < 0) {
                throw new IllegalArgumentException(c.b.a.a.a.B("byteCount < 0: ", j));
            } else if (i == 0) {
                return 0;
            } else {
                try {
                    this.a.g();
                    s w0 = eVar.w0(1);
                    int read = this.b.read(w0.a, w0.c, (int) Math.min(j, (long) (8192 - w0.c)));
                    if (read == -1) {
                        return -1;
                    }
                    w0.c += read;
                    j = (long) read;
                    eVar.b += j;
                    return j;
                } catch (AssertionError e) {
                    if (o.c(e)) {
                        throw new IOException(e);
                    }
                    throw e;
                }
            }
        }

        public void close() throws IOException {
            this.b.close();
        }

        public String toString() {
            StringBuilder g = c.b.a.a.a.g("source(");
            g.append(this.b);
            g.append(")");
            return g.toString();
        }
    }

    public static v a(Socket socket) throws IOException {
        if (socket == null) {
            throw new IllegalArgumentException("socket == null");
        } else if (socket.getOutputStream() != null) {
            p pVar = new p(socket);
            OutputStream outputStream = socket.getOutputStream();
            if (outputStream != null) {
                return new a(pVar, new n(pVar, outputStream));
            }
            throw new IllegalArgumentException("out == null");
        } else {
            throw new IOException("socket's output stream == null");
        }
    }

    public static w b(InputStream inputStream, x xVar) {
        if (inputStream != null) {
            return new a(xVar, inputStream);
        }
        throw new IllegalArgumentException("in == null");
    }

    public static boolean c(AssertionError assertionError) {
        return (assertionError.getCause() == null || assertionError.getMessage() == null || !assertionError.getMessage().contains("getsockname failed")) ? false : true;
    }

    public static w d(Socket socket) throws IOException {
        if (socket == null) {
            throw new IllegalArgumentException("socket == null");
        } else if (socket.getInputStream() != null) {
            p pVar = new p(socket);
            return new b(pVar, b(socket.getInputStream(), pVar));
        } else {
            throw new IOException("socket's input stream == null");
        }
    }
}
